package com.hgb.mall.mbg.mapper;

import com.hgb.mall.mbg.entity.PmsProductCategoryAttributeRelation;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

import javax.annotation.Generated;
import java.util.List;
import java.util.Optional;

import static com.hgb.mall.mbg.mapper.PmsProductCategoryAttributeRelationDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

@Mapper
public interface PmsProductCategoryAttributeRelationMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn.columnList(id, productCategoryId, productAttributeId);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(PmsProductCategoryAttributeRelation record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(productCategoryId).equalTo(record::getProductCategoryId)
                  .set(productAttributeId).equalTo(record::getProductAttributeId);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(PmsProductCategoryAttributeRelation record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(productCategoryId).equalToWhenPresent(record::getProductCategoryId)
                  .set(productAttributeId).equalToWhenPresent(record::getProductAttributeId);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type = SqlProviderAdapter.class, method = "delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type = SqlProviderAdapter.class, method = "insert")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "record.id", before = false, resultType = Long.class)
    int insert(InsertStatementProvider<PmsProductCategoryAttributeRelation> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @ResultMap("PmsProductCategoryAttributeRelationResult")
    Optional<PmsProductCategoryAttributeRelation> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(id = "PmsProductCategoryAttributeRelationResult", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "product_category_id", property = "productCategoryId", jdbcType = JdbcType.BIGINT),
            @Result(column = "product_attribute_id", property = "productAttributeId", jdbcType = JdbcType.BIGINT)
    })
    List<PmsProductCategoryAttributeRelation> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type = SqlProviderAdapter.class, method = "update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, pmsProductCategoryAttributeRelation, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, pmsProductCategoryAttributeRelation, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(PmsProductCategoryAttributeRelation record) {
        return MyBatis3Utils.insert(this::insert, record, pmsProductCategoryAttributeRelation, c ->
                c.map(productCategoryId).toProperty("productCategoryId")
                 .map(productAttributeId).toProperty("productAttributeId")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(PmsProductCategoryAttributeRelation record) {
        return MyBatis3Utils.insert(this::insert, record, pmsProductCategoryAttributeRelation, c ->
                c.map(productCategoryId).toPropertyWhenPresent("productCategoryId", record::getProductCategoryId)
                 .map(productAttributeId).toPropertyWhenPresent("productAttributeId", record::getProductAttributeId)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<PmsProductCategoryAttributeRelation> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, pmsProductCategoryAttributeRelation, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<PmsProductCategoryAttributeRelation> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, pmsProductCategoryAttributeRelation, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<PmsProductCategoryAttributeRelation> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils
                .selectDistinct(this::selectMany, selectList, pmsProductCategoryAttributeRelation, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<PmsProductCategoryAttributeRelation> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, pmsProductCategoryAttributeRelation, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(PmsProductCategoryAttributeRelation record) {
        return update(c ->
                c.set(productCategoryId).equalTo(record::getProductCategoryId)
                 .set(productAttributeId).equalTo(record::getProductAttributeId)
                 .where(id, isEqualTo(record::getId))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(PmsProductCategoryAttributeRelation record) {
        return update(c ->
                c.set(productCategoryId).equalToWhenPresent(record::getProductCategoryId)
                 .set(productAttributeId).equalToWhenPresent(record::getProductAttributeId)
                 .where(id, isEqualTo(record::getId))
        );
    }
}
